home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / AppsToGo / pbClock / IdleTasks.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-22  |  3.7 KB  |  137 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        IdleTasks.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19. /* This function is called when a null event is received.  Do appropriate tasks
  20. ** for null event situations, such as handling balloon help for window. */
  21.  
  22.  
  23.  
  24. /*****************************************************************************/
  25.  
  26.  
  27.  
  28. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  29. #include "App.defs.h"        /* Get various application definitions.            */
  30. #include "App.protos.h"        /* Get the prototypes for application.            */
  31.  
  32. #ifndef __RESOURCES__
  33. #include <Resources.h>
  34. #endif
  35.  
  36. #ifndef __SOUND__
  37. #include <Sound.h>
  38. #endif
  39.  
  40.  
  41.  
  42. /*****************************************************************************/
  43. /*****************************************************************************/
  44.  
  45. #ifdef applec
  46. #pragma segment IdleTasks
  47. #endif
  48.  
  49. /*****************************************************************************/
  50. /*****************************************************************************/
  51.  
  52.  
  53.  
  54. void    DoIdleTasks(EventRecord *event)
  55. {
  56. #ifndef __MWERKS__
  57. #pragma unused (event)
  58. #endif
  59.  
  60.     EventRecord        evt;
  61.     WindowPtr        window;
  62.     FileRecHndl        frHndl;
  63.     TreeObjHndl        root;
  64.     ControlHandle    ctl;
  65.     short            lr, rs;
  66.     long            timer, tick, t1, t2;
  67.     Handle            snd;
  68.     KeyMap            kk;
  69.     short            mm;
  70.  
  71.     if (TSMTEAvailable()) TSMEvent(event);
  72.  
  73.     GetKeys(kk);
  74.     mm  = (kk[1] & 0x8000) ? (cmdKey    ) : 0;
  75.     mm |= (kk[1] & 0x0004) ? (optionKey ) : 0;
  76.     mm |= (kk[1] & 0x0008) ? (controlKey) : 0;
  77.     mm |= (kk[1] & 0x0001) ? (shiftKey  ) : 0;
  78.     evt.what      = nullEvent;        /* Make valid null event, with modifiers. */
  79.     evt.modifiers = mm;
  80.  
  81.     IsCtlEvent(nil, &evt, nil, nil);
  82.  
  83.     /* •••• All of the code below here was added for pbClock. */
  84.  
  85.     for (window = nil; ((window = GetNextWindow(window, 'pbCk')) != nil);) {
  86.         if (!ClocksPaused(window)) {
  87.             frHndl = (FileRecHndl)GetWRefCon(window);
  88.             root   = (*frHndl)->d.doc.root;
  89.             timer  = (*frHndl)->d.doc.timer;
  90.             if (!timer) {
  91.                 (*frHndl)->d.doc.timer = TickCount();
  92.                 continue;
  93.             }
  94.             tick = ((*frHndl)->d.doc.timer = TickCount()) - timer;
  95.             if (tick < 1) continue;
  96.             rs = mDerefRoot(root)->rightStart;
  97.             if (rs > -1) {
  98.                 if (mDerefRoot(root)->timeRemaining[0]) {
  99.                     if (mDerefRoot(root)->timeRemaining[1]) {
  100.                         lr  = mDerefRoot(root)->numMoves[0];
  101.                         lr += mDerefRoot(root)->numMoves[1];
  102.                         lr += rs;
  103.                         lr &= 0x01;
  104.                         t1  = mDerefRoot(root)->timeRemaining[lr];
  105.                         t2  = t1 - tick;
  106.                         if (t2 < 60) t2 = 0;
  107.                         mDerefRoot(root)->timeRemaining[lr] = t2;
  108.                         if ((t1 / 60) != (t2 / 60)) {
  109.                             DrawClock(frHndl, lr);
  110.                             PostEvent(nullEvent, 0L);    /* Don't let PB100 rest. */
  111.                         }
  112.                         if (!t2) {
  113.                             snd = GetResource('snd ', 500);
  114.                             if (snd) SndPlay(nil, snd, false);
  115.                             CNum2Ctl(window, kTabButton, &ctl);
  116.                             UseControlStyle(ctl);
  117.                             HiliteControl(ctl, 255);
  118.                             UseControlStyle(nil);
  119.                             CNum2Ctl(window, kReturnButton, &ctl);
  120.                             UseControlStyle(ctl);
  121.                             HiliteControl(ctl, 255);
  122.                             UseControlStyle(nil);
  123.                             CNum2Ctl(window, kPauseClocks, &ctl);
  124.                             UseControlStyle(ctl);
  125.                             HiliteControl(ctl, 255);
  126.                             UseControlStyle(nil);
  127.                         }
  128.                     }
  129.                 }
  130.             }
  131.         }
  132.     }
  133. }
  134.  
  135.  
  136.  
  137.